from functools import reduce

# 基础用法
numbers = [1, 2, 3, 4, 5]

# 求和
total = reduce(lambda x, y: x + y, numbers)
print(total)  # 输出: 15

# 求积
product = reduce(lambda x, y: x * y, numbers)
print(product)  # 输出: 120

# 求最大值
max_value = reduce(lambda x, y: x if x > y else y, numbers)
print(max_value)  # 输出: 5

# 带初始值
result = reduce(lambda x, y: x + y, numbers, 10)
print(result)  # 输出: 25

# 实际应用：字符串拼接
words = ['Hello', 'World', 'Python']
sentence = reduce(lambda x, y: x + ' ' + y, words)
print(sentence)  # 输出: Hello World Python